package com.tc.controller;

import com.github.pagehelper.PageInfo;
import com.tc.pojo.BusDetails;
import entity.Result;
import entity.StatusCode;
import io.swagger.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/
@Api(value = "BusDetailsController")
@RestController
@RequestMapping("/BusDetails")
@CrossOrigin
public class BusDetailsController {

    @Autowired
    private com.tc.service.BusDetailsService BusDetailsService;

    /***
     * BusDetails分页条件搜索实现
     * @param BusDetails
     * @param page
     * @param size
     * @return
     */
    @ApiOperation(value = "BusDetails条件分页查询",notes = "分页条件查询BusDetails方法详情",tags = {"BusDetailsController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "BusDetails对象",value = "传入JSON数据",required = false) BusDetails BusDetails, @PathVariable  int page, @PathVariable  int size){
        //调用BusDetailsService实现分页条件查询BusDetails
        PageInfo<com.tc.pojo.BusDetails> pageInfo = BusDetailsService.findPage(BusDetails, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * BusDetails分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @ApiOperation(value = "BusDetails分页查询",notes = "分页查询BusDetails方法详情",tags = {"BusDetailsController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用BusDetailsService实现分页查询BusDetails
        PageInfo<BusDetails> pageInfo = BusDetailsService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param BusDetails
     * @return
     */
    @ApiOperation(value = "BusDetails条件查询",notes = "条件查询BusDetails方法详情",tags = {"BusDetailsController"})
    @PostMapping(value = "/search" )
    public Result<List<BusDetails>> findList(@RequestBody(required = false) @ApiParam(name = "BusDetails对象",value = "传入JSON数据",required = false) BusDetails BusDetails){
        //调用BusDetailsService实现条件查询BusDetails
        List<com.tc.pojo.BusDetails> list = BusDetailsService.findList(BusDetails);
        return new Result<List<com.tc.pojo.BusDetails>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @ApiOperation(value = "BusDetails根据ID删除",notes = "根据ID删除BusDetails方法详情",tags = {"BusDetailsController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Integer id){
        //调用BusDetailsService实现根据主键删除
        BusDetailsService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改BusDetails数据
     * @param BusDetails
     * @param id
     * @return
     */
    @ApiOperation(value = "BusDetails根据ID修改",notes = "根据ID修改BusDetails方法详情",tags = {"BusDetailsController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @PutMapping(value="/{id}")
    public Result update(@RequestBody @ApiParam(name = "BusDetails对象",value = "传入JSON数据",required = false) BusDetails BusDetails, @PathVariable Integer id){
        //设置主键值
        BusDetails.setId(id);
        //调用BusDetailsService实现修改BusDetails
        BusDetailsService.update(BusDetails);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增BusDetails数据
     * @param BusDetails
     * @return
     */
    @ApiOperation(value = "BusDetails添加",notes = "添加BusDetails方法详情",tags = {"BusDetailsController"})
    @PostMapping
    public Result add(@RequestBody  @ApiParam(name = "BusDetails对象",value = "传入JSON数据",required = true) BusDetails BusDetails){
        //调用BusDetailsService实现添加BusDetails
        BusDetailsService.add(BusDetails);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询BusDetails数据
     * @param id
     * @return
     */
    @ApiOperation(value = "BusDetails根据ID查询",notes = "根据ID查询BusDetails方法详情",tags = {"BusDetailsController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @GetMapping("/{id}")
    public Result<BusDetails> findById(@PathVariable Integer id){
        //调用BusDetailsService实现根据主键查询BusDetails
        BusDetails BusDetails = BusDetailsService.findById(id);
        new SQL().INSERT_INTO("user").VALUES("uname","yufei2B");
        return new Result<com.tc.pojo.BusDetails>(true,StatusCode.OK,"查询成功",BusDetails);

    }

    /***
     * 查询BusDetails全部数据
     * @return
     */
    @ApiOperation(value = "查询所有BusDetails",notes = "查询所BusDetails有方法详情",tags = {"BusDetailsController"})
    @GetMapping
    public Result<List<BusDetails>> findAll(){
        //调用BusDetailsService实现查询所有BusDetails
        List<BusDetails> list = BusDetailsService.findAll();
        return new Result<List<BusDetails>>(true, StatusCode.OK,"查询成功",list) ;
    }

    /**
     * 点击某个商品遍历详情
     * @param
     * @return
     */

    @GetMapping("product/{id}")
    public Result<Map> gotoProduct(@PathVariable Integer id){
        Map data=BusDetailsService.findProduct(id);
        return new Result(true, StatusCode.OK,"查询成功",data) ;
    }

}
